﻿namespace _3_NovaAdmin.Domain.Abstractions;

/// <summary>
/// 审计功能基类（同时适用于单主键和复合主键）
/// 如果继承AuditableEntity<TKey>,则实体类必须要配置CreationAuditInfo与EditAuditInfo的关系，EF Core是没办法知道映射关系的
/// </summary>
/// <typeparam name="TKey"></typeparam>
public abstract class AuditableEntity<TKey> : Entity, IAuditable<TKey>
    where TKey : notnull
{
    public CreationAuditInfo<TKey> CreationAuditInfo { get; private set; }
    public EditAuditInfo<TKey>? EditAuditInfo { get; private set; }

    public void ChangeCreationAudit(CreationAuditInfo<TKey> auditInfo)
        => CreationAuditInfo = auditInfo;

    public void ChangeEditAuditInfo(EditAuditInfo<TKey> auditInfo)
        => EditAuditInfo = auditInfo;
}
